<template>
	<div class="cartcontrol">
		<transition name="move">
			<div class="cart-decrease icon-remove_circle_outline" v-show="food.count>0" @click.stop.prevent="decreaseCart">
			</div>
		</transition>
		<div class="cart-count" v-show="food.count>0">
			{{food.count}}
		</div>
		<div class="cart-add icon-add_circle" @click.stop.prevent="addCart">
		</div>
	</div>
</template>

<script type="text/ecmascript-6">
	import Vue from 'vue';

	export default {
		props: {
			food: {
				type: Object
			}
		},
		created() {
		},
		methods: {
			addCart(event) {
				if(!this.food.count) {
					Vue.set(this.food, 'count', 1);
					this.food.count = 1;
				} else {
					this.food.count++;
				}
				this.$emit('cartAdd', event.target);
			},
			decreaseCart() {
				if(this.food.count) {
					this.food.count--;
				}
			}
		}
	};
</script>

<style lang="less">
	@import '../../common/less/z.less';
	@import '../../common/less/css3.less';
	@import '../../common/less/appstyle.less';
	.cartcontrol {
		.cart-decrease {
			.d-ib();
			padding: 6px;
			line-height: 24px;
			.font-s24();
			color: rgb(0, 160, 220);
			&.move-enter-active,
			&.move-leave-active {
				transition: all 0.4s linear;
			}
			&.move-enter,
			&.move-leave-active {
				.opa(0);
				transform: translate3d(24px, 0, 0);
			}
		}
		.cart-count {
			.d-ib();
			vertical-align: top;
			width: 12px;
			padding-top: 6px;
			line-height: 24px;
			.tc();
			.font-s10();
			color: rgb(147, 163, 159);
		}
		.cart-add {
			.d-ib();
			padding: 6px;
			line-height: 24px;
			.font-s24();
			color: rgb(0, 160, 220);
		}
	}
</style>